const http = require('http');
const fs = require('fs');

const server = http.createServer();

server.on('request', (req, res) => {
    // 解决跨域问题
    res.setHeader('Access-Control-Allow-Origin', '*');

    res.writeHead(200, {
        "content-type": "text/plain;charset=utf-8"
    });

    fs.readFile('data/product.json', (err, data) => {
        res.end(data);
    });
});

server.listen(3000, () => {
    console.log('服务器创建成功! http://localhost:3000');
});